package com.cqupt.slewing.room

import android.app.Application
import androidx.lifecycle.AndroidViewModel
import androidx.lifecycle.LiveData

class ItemViewModel(application: Application) : AndroidViewModel(application) {
    private val itemDatabase: ItemDatabase = ItemDatabase.getDatabase(application)
    private val itemDao: ItemDao = itemDatabase.getItemDao()

    suspend fun insert(item: Item) {
        itemDao.insertItems(item)
    }

    suspend fun clear() {
        itemDao.clear()
    }

    suspend fun getItemByMac(macID: String): Item {
        return itemDao.findByMac(macID)
    }

    suspend fun removeItem(item: Item) {
        itemDao.delete(item)
    }

    fun getAllItemsLive(): LiveData<List<Item>> {
        return itemDao.getAllItemsLive()
    }
}